package com.pollux.result;

import lombok.Data;

/**
 * @Author: pollux
 * @CreateTime: 2024-10-30
 * @Description: 统一响应类
 * @Version: 1.0
 */


public class Result<T> {
    private static final Integer SUCCESS  = 1;
    private static final Integer ERROR = 0;

    private Integer code;
    private String msg;
    private T data;

    /**
     * @param data 返回数据
     * @description: 有数据的成功返回
     * @return: com.pollux.result.Result<T>
     * @author: pollux
     * @date: 2024/10/30 16:11
     */
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.code = SUCCESS;
        result.data = data;
        return result;
    }

    /**
     * @description: 无数据的成功返回
     * @return: com.pollux.result.Result<T>
     * @author: pollux
     * @date: 2024/10/30 16:11
     */
    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.code = SUCCESS;
        return result;
    }

    /**
     * @param msg 错误消息
     * @description: 错误返回
     * @return:  com.pollux.result.Result<T>
     * @author: pollux
     * @date: 2024/10/30 16:12
     */
    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<>();
        result.code = ERROR;
        result.msg = msg;
        return result;
    }
}























